import {
	jsonp
} from 'vue-jsonp'; //安装完成组件引用
import QQMapWX from "@/utils/map/qqmap-wx-jssdk.js"


export function getLocation() {
	let that = this;
	const key = "7WVBZ-KCTCF-JXIJD-JDXRH-SDHCQ-KKF5J" // 替换为你的高德、百度或腾讯地图API的key



	return new Promise((resolve) => {

		//位置信息默认数据
		let location = {
			longitude: 0,
			latitude: 0,
			province: "",
			city: "",
			area: "",
			street: "",
			address: "",
		};
		uni.showModal({
			title: '授权申请',
			content: '我门申请获取您的位置,以便展示最近的商家',
			success: function(res) {
				if (res.confirm) {


					uni.getLocation({
						type: "gcj02",
						success(res) {
							location.longitude = res.longitude;
							location.latitude = res.latitude;
							// 腾讯地图Api
							const qqmapsdk = new QQMapWX({
								key: key //这里填写自己申请的key
							});
							qqmapsdk.reverseGeocoder({
								location,
								success(response) {
									let info = response.result;
									console.log(info);
									location.province = info.address_component
										.province;
									location.city = info.address_component.city;
									location.area = info.address_component.district;
									location.street = info.address_component.street;
									location.address = info.address;
									resolve(location);
								},
							});
						},
						fail(err) {
							console.log(err)
							resolve(location);
						},
					});
				} else if (res.cancel) {
					resolve(null);
				}
			}
		});



	});

}